package com.wr;

import java.util.concurrent.atomic.AtomicInteger;

public class VolitaleDemo13 {

    private volatile static AtomicInteger atomicInteger = new AtomicInteger(10);   // 原子类  原子Integer10

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                for (int i1 = 0; i1 < 10; i1++) {
                    atomicInteger.getAndIncrement();  // +1操作
                }
            }).start();
        }
        System.out.println(Thread.activeCount()+"----1");
        while (Thread.activeCount()>2){
            Thread.yield();
        }
        System.out.println(Thread.activeCount()+"----2");
        System.out.println(atomicInteger);
    }
}
